package javaAPI.String.String2;

import java.util.Scanner;

public class String4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int money ;
        while (true) {
            System.out.println("请录入一个金额");
            money = sc.nextInt();
            if (money >= 0 && money <= 9999999) {
                break;
            } else {
                System.out.println("金额无效");
            }
        }
        //定义变量来表示money的大写;
        String moneyStr="";
        //2.得到money的每一个数字，将之转为中文
        while(true){
            //从右往左获得数据，因为最右侧是数据的个位;
            int ge=money%10;
            String CapitalNumber=GetCapitalNumber(ge);
            moneyStr=CapitalNumber+moneyStr;
            //去掉刚刚获得的数据
            money =money/10;
            if(money==0){
                break;
            }
        }
        //3.补0
        int count=7-moneyStr.length();
        for (int i = 0; i < count; i++) {
            moneyStr="零"+moneyStr;
        }
        System.out.println(moneyStr);
        //4.插入单位
        String []arr={"佰","拾","万","仟","佰","拾","元",};
        String result="";
        for (int i = 0; i < moneyStr.length(); i++) {
            char c=moneyStr.charAt(i);
            //将大写数字和单位拼写到result中
            result=result+c+arr[i];
        }
        System.out.println(result);
    }

    //定义方法将数字变为大写
    public  static String GetCapitalNumber(int number){
        String []arr={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};

    return arr[number];
    }
}
